package net.http;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * HTTP response. Return one of these from serve().
 */
public class Response {
	// TODO get rid of response class
	/**
	 * HTTP status code after processing, e.g. "200 OK", HTTP_OK
	 */
	public int statusCode;

	/**
	 * MIME type of content, e.g. "text/html"
	 */
	public String mimeType;

	/**
	 * Data of the response, may be null.
	 */
	public InputStream data;

	public long contentLength = 0;
	/**
	 * Default constructor: response = HTTP_OK, data = mime = 'null'
	 */
	public Response() {
		this.statusCode = FileHttpHandler.SC_OK;
	}

	/**
	 * Basic constructor.
	 */
	public Response(int statusCode, String mimeType, InputStream data) {
		this.statusCode = statusCode;
		this.mimeType = mimeType;
		this.data = data;
	}

	/**
	 * Convenience method that makes an InputStream out of given text.
	 */
	public Response(int statusCode, String mimeType, String txt) {
		this.statusCode = statusCode;
		this.mimeType = mimeType;
		this.data = new ByteArrayInputStream(txt.getBytes());
	}
}